﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FrameWork.Output;
using FrameWork.Log;

namespace FrameWork.Output
{
    /// <summary>
    /// 为可Log类型对象提供输出采集
    /// </summary>
    public abstract class LogableOutputCollector:OutputCollectorBase
    {

        public override event OutputCollectorBase.NewOutputGetEventHandler NewOutputGet;
        private LogableClassBase Oper;

        public override void Start()
        {
            Oper.LogAvilable += Oper_LogAvilable;
        }

        void Oper_LogAvilable(object sender, LogAvilableEventArgs e)
        {
            OutputType type = (OutputType)(e.LogType);
            OutputItem i = new OutputItem(type, e.Message, e.Tag, e.Message);
            OutputEventArgs e1 = new OutputEventArgs(i);
            if (NewOutputGet != null)
                NewOutputGet(this, e1);
        }

        public override void Stop()
        {
            Oper.LogAvilable -= Oper_LogAvilable;
        }

        public LogableOutputCollector(LogableClassBase Oper)
        {
            this.Oper = Oper;
        }

        protected void OnNewOutputGet(object sender,OutputEventArgs e)
        {
            if(NewOutputGet!=null)
            {
                NewOutputGet(sender, e);
            }
        }

    }
}
